function [s] = formatNumber(value, includeParentheses, varargin)
	if length(varargin) >= 1 && ~isempty(varargin{1})
		NumDigitsAfterComma = varargin{1};
	else
		NumDigitsAfterComma = 2;
	end

	if value == 0
		s = '0';
	else
		magnitudeOrder = floor(log10(abs(value)));
		if magnitudeOrder >= 6
			s	= sprintf('%.1e', value);
		else if magnitudeOrder >= 1-(NumDigitsAfterComma)
			mystr = sprintf('%%.0%df', NumDigitsAfterComma);
			s = sprintf(mystr, value);
		else
			mystr = sprintf('%%.%df', NumDigitsAfterComma); % decimal notation
			s	= sprintf(mystr, value);
		end
		end	
	end
	
	if includeParentheses
		s = sprintf('(%s)', s);
	end
end